import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '../store';

interface userBaseInfoState {
    userId: number;
    username: string;
}

const initialState: userBaseInfoState = {
    userId: -1,
    username: '',
};

export const userBaseInfoSlice = createSlice({
    name: 'userBaseInfo',
    initialState,
    reducers: {
        addUserBaseInfo: (state, action: PayloadAction<userBaseInfoState>) => {
            state.userId = action.payload.userId;
            state.username = action.payload.username;
        },
    },
});

export const { addUserBaseInfo } = userBaseInfoSlice.actions;
export const selectUserBaseInfo = (state: RootState) => state.userBaseInfo;
export default userBaseInfoSlice.reducer;
